package com.gitee.wsl.compose.ext.input

import androidx.compose.foundation.text.KeyboardActionScope
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager


/**
 * @param onOther an actions to be run when you specify one that is not the one that can be handled by focusManager
 *   e.g. Go, Search, and Send. By default does nothing.
 */
@Composable
fun KeyboardActions.Companion.default(
    onProceed: (KeyboardActionScope.() -> Unit)? = null
): KeyboardActions = LocalFocusManager.current.run {
    remember {
        KeyboardActions(
            onDone = { clearFocus() },
            onNext = { moveFocus(FocusDirection.Next) },
            onPrevious = { moveFocus(FocusDirection.Previous) },
            onGo = onProceed,
            onSearch = onProceed,
            onSend = onProceed,
        )
    }
}